<template>
  <div class="collapsible-thought">
    <div class="thought-header" @click="toggle">
      <span class="toggle-icon" :class="{ open: isOpen }">{{ isOpen ? '−' : '+' }}</span>
      <span class="header-text">思考过程</span>
    </div>
    <transition name="slide">
      <div v-show="isOpen" class="thought-content">
        <slot></slot>
      </div>
    </transition>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const isOpen = ref(false)

const toggle = () => {
  isOpen.value = !isOpen.value
}
</script>

<style scoped>
.collapsible-thought {
  margin: 10px 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  background-color: var(--input-bg);
}

.thought-header {
  padding: 8px 12px;
  background-color: var(--sidebar-active);
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.toggle-icon {
  font-weight: bold;
  margin-right: 8px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

.toggle-icon.open {
  transform: rotate(0deg);
}

.toggle-icon:not(.open) {
  transform: rotate(0deg);
}

.header-text {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 14px;
}

.thought-content {
  padding: 12px;
  background-color: var(--input-bg);
  border-top: 1px solid var(--border-color);
  overflow-x: auto;
}

.thought-content div {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
  padding: 0;
  color: var(--text-primary);
  overflow-x: auto;
}

.slide-enter-active {
  transition: all 0.3s ease-out;
}

.slide-leave-active {
  transition: all 0.3s ease-in;
}

.slide-enter-from,
.slide-leave-to {
  max-height: 0;
  opacity: 0;
  transform: translateY(-10px);
}

.slide-enter-to,
.slide-leave-from {
  max-height: 1000px;
  opacity: 1;
  transform: translateY(0);
}
</style>